import 'package:flutter/material.dart';
// import 'package:fluttertoast/fluttertoast.dart';

class DialogDemo extends StatefulWidget {
  DialogDemo({Key? key}) : super(key: key);

  @override
  State<DialogDemo> createState() => _DialogDemoState();
}

class _DialogDemoState extends State<DialogDemo> {
  _alertDialog() async {
    var res = await showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
              title: Text("提示信息"),
              content: Text("您确定要删除吗?"),
              actions: <Widget>[
                FlatButton(
                    onPressed: () {
                      print("取消");
                      Navigator.pop(context, 'Cancle');
                    },
                    child: Text("取消")),
                FlatButton(
                    onPressed: () {
                      print("确定");
                      Navigator.pop(context, 'Ok');
                    },
                    child: Text("确定")),
              ]);
        });
    print(res);
  }

  _simpleDialog() async {
    var res = await showDialog(
        context: context,
        builder: (context) {
          return SimpleDialog(
            title: Text("选择内容"),
            children: <Widget>[
              SimpleDialogOption(
                child: Text("option a"),
                onPressed: () {
                  print("option a");
                  Navigator.pop(context, 'a');
                },
              ),
              Divider(),
              SimpleDialogOption(
                child: Text("option b"),
                onPressed: () {
                  print("option b");
                  Navigator.pop(context, 'b');
                },
              ),
              Divider(),
              SimpleDialogOption(
                child: Text("option c"),
                onPressed: () {
                  print("option c");
                  Navigator.pop(context, 'c');
                },
              ),
              Divider(),
            ],
          );
        });
    print(res);
  }

  _modelBottomSheet() async {
    var res = await showModalBottomSheet(
        context: context,
        builder: (context) {
          return Container(
            height: 240,
            child: Column(
              children: <Widget>[
                ListTile(
                  title: Text("分享 A"),
                  onTap: () {
                    Navigator.pop(context, 'A');
                  },
                ),
                Divider(),
                ListTile(
                  title: Text("分享 B"),
                  onTap: () {
                    Navigator.pop(context, 'B');
                  },
                ),
                Divider(),
                ListTile(
                  title: Text("分享 C"),
                  onTap: () {
                    Navigator.pop(context, 'C');
                  },
                ),
                Divider(),
              ],
            ),
          );
        });
    print(res);
  }

  _toast() async {
    // Fluttertoast.showToast(
    //     msg: "提示信息",
    //     toastLength: Toast.LENGTH_SHORT,
    //     gravity: ToastGravity.CENTER,
    //     timeInSecForIosWeb: 1,
    //     backgroundColor: Colors.black,
    //     textColor: Colors.white,
    //     fontSize: 16.0);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("dialog"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              onPressed: _alertDialog,
              child: Text("alert弹出框-AlertDialog"),
            ),
            SizedBox(height: 20),
            RaisedButton(
              onPressed: _simpleDialog,
              child: Text("select弹出框-SimpleDialog"),
            ),
            SizedBox(height: 20),
            RaisedButton(
              onPressed: _modelBottomSheet,
              child: Text("ActionSheet弹出框-showModelBottomSheet"),
            ),
            SizedBox(height: 20),
            RaisedButton(
              onPressed: _toast,
              child: Text("toast-fluttertoast第三方库"),
            ),
          ],
        ),
      ),
    );
  }
}
